# import os
import logging.config
# import logging.config
# import time
# """
# logging配置
# """

def writeLog(log_file_path):
    # 定义三种日志输出格式 开始
    standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
                    '[%(levelname)s][%(message)s]'  # 其中name为getlogger指定的名字

    # console_format = '[%(asctime)s][task_id:%(name)s][%(filename)s:%(lineno)d]' \
    #                 '[%(levelname)s][%(message)s]'  # 其中name为getlogger指定的名字

    # simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
    # simple_format = '%(message)s'
    # sender_format = 'From sender :  %(message)s'
  


    # log文件的全路径
    # log_file_path = os.path.join("D:\work\log", "\MBAFClog.log")
    log_file_fullpath = log_file_path+"_log.log"
    # print("log_file_fullpath="+log_file_fullpath)
    # app_file_path = os.path.join("D:\work\log", "\MBAFC_Applog.log")
    # app_file_path = log_file_path+"_Applog.log"
    # # print("app_file_path="+app_file_path)
    # # send_file_path = os.path.join("D:\work\log", "\MBAFC_Sendlog.log")
    # send_file_path = log_file_path+"_Sendlog.log"
    # print("send_file_path="+send_file_path)

    # log配置字典
    LOGGING_DIC = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'standard': {
                'format': standard_format
            }
        },
        'filters': {},
        'handlers': {
            # 打印到终端的日志
            'console': {
                'level': 'INFO',
                'class': 'logging.StreamHandler',  # 打印到屏幕
                'formatter': 'standard'
            },
            # 打印到文件的日志,收集info及以上的日志
            'default': {
                'level': 'INFO',
                'class': 'logging.handlers.RotatingFileHandler',  # 保存到文件
                'formatter': 'standard',
                'filename': log_file_fullpath,  # 日志文件
                'maxBytes': 1024*1024*50,  # 日志大小 5M
                'backupCount': 20,
                'encoding': 'utf-8',  # 日志文件的编码，再也不用担心中文log乱码了
            }
        },
        'loggers': {
            # logging.getLogger(__name__)拿到的logger配置
            'dev': {
                'handlers': ['default','console'],  # 这里把上面定义的两个handler都加上，即log数据既写入文件又打印到屏幕
                'level': 'INFO',
                'propagate': True,  # 向上（更高level的logger）传递
            },            
        },
    }

    logging.config.dictConfig(LOGGING_DIC)  # 导入上面定义的logging配置
logger = logging.getLogger('dev')  # 生成一个log实例
    # send_logger = logging.getLogger('prod')  # 生成一个log实例


# if __name__ == '__main__':
#     for i in range(10):
#         logger.info('It works! {}'.format(i))  # 记录该文件的运行状态
#         send_logger.info('hhhhh --> {}'.format(i))